<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2006/12/18 19:11:27 $)
// $RCSfile: setup.php,v $ : $Revision: 1.3 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

/**
* Called when the module is to be installed
*/
function _troubleshooter_install($action, $page = '') {
	global $_SWIFT, $__LANG;

	if ($action == "getpages")
	{
		return "1";
	} else if ($action == "buildpage") {
		$_SWIFT["query"]["create"]["troubleshootercat"] = "CREATE TABLE ". TABLE_PREFIX ."troubleshootercat (
																				troubleshootercatid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																				staffid INT UNSIGNED NOT NULL DEFAULT '0',
																				title VARCHAR(255) NOT NULL DEFAULT '',
																				description VARCHAR(255) NOT NULL DEFAULT '',
																				dateline INT UNSIGNED NOT NULL DEFAULT '0',
																				displayorder INT UNSIGNED NOT NULL DEFAULT '0',
																				views INT UNSIGNED NOT NULL DEFAULT '0',
																				PRIMARY KEY (troubleshootercatid)
																			);";

		$_SWIFT["query"]["create"]["troubleshootersteps"] = "CREATE TABLE ". TABLE_PREFIX ."troubleshootersteps (
																				troubleshooterid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																				troubleshootercatid INT UNSIGNED NOT NULL DEFAULT '0',
																				staffid INT UNSIGNED NOT NULL DEFAULT '0',
																				subject VARCHAR(255) NOT NULL DEFAULT '',
																				dateline INT UNSIGNED NOT NULL DEFAULT '0',
																				edited SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																				editedstaffid INT UNSIGNED NOT NULL DEFAULT '0',
																				displayorder INT UNSIGNED NOT NULL DEFAULT '0',
																				views INT UNSIGNED NOT NULL DEFAULT '0',
																				totalcomments INT UNSIGNED NOT NULL DEFAULT '0',
																				redirecttickets SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																				redirectdepartmentid INT UNSIGNED NOT NULL DEFAULT '0',
																				PRIMARY KEY (troubleshooterid),
																				KEY troubleshootersteps1 (troubleshootercatid)
																			);";

		$_SWIFT["query"]["create"]["troubleshooterdata"] = "CREATE TABLE ". TABLE_PREFIX ."troubleshooterdata (
																				troubleshooterdataid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																				troubleshooterid INT UNSIGNED NOT NULL DEFAULT '0',
																				contents MEDIUMTEXT,
																				PRIMARY KEY (troubleshooterdataid),
																				KEY troubleshooterdata1 (troubleshooterid)
																			);";

		$_SWIFT["query"]["create"]["troubleshooterlinks"] = "CREATE TABLE ". TABLE_PREFIX ."troubleshooterlinks (
																				troubleshooterlinkid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																				troubleshootercatid INT UNSIGNED NOT NULL DEFAULT '0',
																				parenttroubleshooterid INT UNSIGNED NOT NULL DEFAULT '0',
																				childtroubleshooterid INT UNSIGNED NOT NULL DEFAULT '0',
																				PRIMARY KEY (troubleshooterlinkid),
																				UNIQUE KEY (troubleshootercatid, parenttroubleshooterid, childtroubleshooterid)
																			);";

		$_SWIFT["query"]["insert"]["settings"][0] = "INSERT INTO `". TABLE_PREFIX ."settings`(`section`, `vkey`, `data`) VALUES('registeredmodules', '". MODULE_TROUBLESHOOTER ."', '1')";
	}
}

/**
* Called when the module is to be UNinstalled
*/
function _troubleshooter_uninstall() {
	global $_SWIFT, $__LANG;

	// Drop the necessary module tables
	$_SWIFT["query"]["drop"]["troubleshootercat"] = "DROP TABLE `". TABLE_PREFIX ."troubleshootercat`;";
	$_SWIFT["query"]["drop"]["troubleshootersteps"] = "DROP TABLE `". TABLE_PREFIX ."troubleshootersteps`;";
	$_SWIFT["query"]["drop"]["troubleshooterdata"] = "DROP TABLE `". TABLE_PREFIX ."troubleshooterdata`;";
	$_SWIFT["query"]["drop"]["troubleshooterlinks"] = "DROP TABLE `". TABLE_PREFIX ."troubleshooterlinks`;";

	// Unregister the module
	$_SWIFT["query"]["update"]["settings"][0] = "DELETE FROM `". TABLE_PREFIX ."settings` WHERE `section` = 'registeredmodules' AND `vkey` = '". MODULE_TROUBLESHOOTER ."';";
}

?>